<template>
  <div class="login-container">
    <!-- 背景图 -->
    <div class="logo">
      <!-- 表单区域盒子 -->
      <div class="box">
        <!-- <span class="borderLine"></span> -->
        <!-- 登录表单 -->
        <el-form
          ref="loginForm"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
          auto-complete="on"
          label-position="left"
        >
          <!-- 表单标题 -->
          <h2 style="color:#ccc">SCMS配置管理系统</h2>
          <!-- 账号输入框 -->
          <el-form-item prop="username" class="inputBox">
            <el-input
              ref="username"
              v-model="loginForm.username"
              placeholder="Username"
              name="username"
              type="text"
              tabindex="1"
              auto-complete="on"
            />
          </el-form-item>
          <!-- 密码输入框 -->
          <el-form-item prop="password" class="inputBox">
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.password"
              :type="passwordType"
              placeholder="Password"
              name="password"
              tabindex="2"
              @keyup.enter.native="handleLogin"
            />
          </el-form-item>
          <!-- 登录按钮 -->
          <el-form-item>
            <el-button
              :loading="loading"
              type="primary"
              style="width: 300px; margin-bottom: 30px;height:40px;margin-top:30px"
              @click.native.prevent="handleLogin"
            >登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import { validUsername } from "@/utils/validate";

export default {
  name: "Login",
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!validUsername(value)) {
        callback(new Error("请输入正确的用户名"));
      } else {
        callback();
      }
    };
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("密码不能少于6位数字"));
      } else {
        callback();
      }
    };
    return {
      loginForm: {
        username: "admin",
        password: "000000"
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", validator: validateUsername }
        ],
        password: [
          { required: true, trigger: "blur", validator: validatePassword }
        ]
      },
      loading: false,
      passwordType: "password",
      redirect: undefined
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (
          valid &&
          this.loginForm.username === "admin" &&
          this.loginForm.password === "000000"
        ) {
          this.loading = true;
          this.$router.push({ path: this.redirect || "/" });
          this.loading = false;
        } else {
          this.$message.error("登录失败");
          this.loading = false;
          return false;
        }
      });
    }
    // handleLogin() {
    //   this.$refs.loginForm.validate((valid) => {
    //     if (valid) {
    //       this.loading = true;
    //       this.$store
    //         .dispatch("user/login", this.loginForm)
    //         .then(() => {
    //           this.$router.push({ path: this.redirect || "/" });
    //           this.loading = false;
    //         })
    //         .catch(() => {
    //           this.loading = false;
    //         });
    //     } else {
    //       console.log("error submit!!");
    //       return false;
    //     }
    //   });
    // },
  }
};
</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;

  .logo {
    // flex: 3;

    // filter: brightness(1.1);
    width: 100%;

    background: url("../../assets/imgs/login2.jpg") no-repeat center / cover;
    // border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
  }
  .form {
    // flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 176px;
    .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }
    .el-checkbox {
      color: #606266;
    }
  }
}
</style>

<style  scoped>
/* 整体登陆盒子 */
.box {
  /* flex: ; */
  position: relative;
  width: 380px;
  height: 420px;
  /* background: #283443; */
  background: transparent;
  /* background-color: rgba(255, 255, 255, 0.5); */
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #a9a9a9;
  /* color: #fff; */
  /* backdrop-filter: blur(10px); */

  /* border: 2px solid #a9a9a9; */
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  /* transition: transform 0.7s ease; */
  transition-property: transform, box-shadow;
  transition-duration: 0.7s;
  transition-timing-function: ease;
  /* transition: filter 0.3s ease; */
}
.box:hover {
  /* backdrop-filter: blur(10px); */
  /* border: 2px solid #a9a9a9; */

  transform: translateY(-10px);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
  /* color: #00d0ff; */
}

/* 登录form表单 */
.box form {
  position: absolute;
  inset: 4px;
  /* background: #283443; */
  /* background-color: rgba(255, 255, 255, 1); */
  background: transparent;

  padding: 50px 40px;
  border-radius: 8px;
  z-index: 2;
  display: flex;
  flex-direction: column;
}
/* 标题 */
.box form h2 {
  color: #355;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.1em;
  /* font-size: 6em; */
  /* color: #333; */
  position: relative;
}
/* 4.变色文字样式 */
.box form h2::after {
  content: "SCMS配置管理系统";
  position: absolute;
  top: 0;
  left: 26px;
  /* color: teal; */
  /* clip-path: ellipse(100px 100px at 50% center); */
  animation: animate1 7s ease-in-out infinite;
  background-image: linear-gradient(
    60deg,
    #00d0ff,
    #4dff03,
    #ff0058,
    #ffbc00,
    #ff0058
  );
  background-clip: text;
  color: transparent;
}

/* 5.聚光灯动画 */
@keyframes animate1 {
  0%,
  100% {
    clip-path: ellipse(100px 100px at 0% center);
  }
  50% {
    clip-path: ellipse(100px 100px at 100% center);
  }
}
/* 输入框盒子 */
.box form .inputBox {
  position: relative;
  width: 300px;
  margin-top: 35px;
}
/* 输入框 */
.box form .inputBox input {
  position: relative;
  width: 100%;
  padding: 20px 10px 10px;
  background: transparent;
  outline: none;
  border: none;
  box-shadow: none;
  /* color: #23242a; */
  font-size: 1em;
  letter-spacing: 0.05em;
  transition: 0.5s;
  z-index: 10;
}

::v-deep .el-input__inner {
  background-color: transparent;
  backdrop-filter: blur(8px);
  /* color: #00d0ff; */
  color: #fff;
  /* border: 1px solid #ccc; */
}
/* username和passward文字样式 */
.box form .inputBox span {
  position: absolute;
  left: 0;
  padding: 20px 0px 10px;
  pointer-events: none;
  color: #8f8f8f;
  font-size: 1em;
  letter-spacing: 0.05em;
  transition: 0.5s;
}
/* 有效输入和获取焦点时 span上移 文字减小 */
.box form .inputBox input:valid ~ span,
.box form .inputBox input:focus ~ span {
  color: #fff;
  font-size: 0.75em;
  transform: translateY(-34px);
}
/* 白色横线 */
.box form .inputBox i {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 2px;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
  transition: 0.5s;
  pointer-events: none;
}
/* 有效输入和获取焦点时  横线变高 */
.box form .inputBox input:valid ~ i,
.box form .inputBox input:focus ~ i {
  height: 44px;
}
/* 忘记密码和注册盒子 */
.box form .links {
  display: flex;
  justify-content: space-between;
}
/* a链接 */
.box form .links a {
  margin: 10px 0;
  font-size: 0.75em;
  color: #8f8f8f;
  text-decoration: none;
}
/* hover时忘记密码变白  注册直接白色 */
.box form .links a:hover,
.box form .links a:nth-child(2) {
  color: #fff;
}
/* 登录按钮样式 */
/* .box form .btn {
  border: none;
  outline: none;
  padding: 9px 25px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9em;
  border-radius: 4px;
  font-weight: 600;
  width: 100px;
  margin-top: 10px;
} */
/* 鼠标按下时 登录按钮整体透明80% */
.box form .btn:active {
  opacity: 0.8;
}
</style>